package com.springapp.jsonmodel;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.springapp.model.Cathegory;
import com.springapp.model.Item;
import com.springapp.util.ControllerUtil;

public class JsonHelper {
	
	private static Gson gson;
	private static GsonBuilder gsonBuilder;

	private static Gson gsoner () {
		if (gsonBuilder == null)
		{
			gsonBuilder =  new  GsonBuilder();
        	gson = gsonBuilder.create();			
		}
		return gson;
	}
	
//json: {"description":"category_description","categoryId":4,"price":999.99,"name":"item_name","id":3}	
	public static String fromModel(Item item) {
		ItemJson itemJson = new ItemJson(
				item.getId(),
				item.getCathegory().getId(),			
				item.getPrice(),
				item.getDescription(),
				item.getName()
				);
		
		String StringItemJson = gsoner().toJson(itemJson);
		
		return StringItemJson;
	}
	
	Item toModel (String json) {
		
		return null;
	}
}
